//
//  LoginC.m
//  GuiJuWo
//
//  Created by chenguibang on 16/3/26.
//  Copyright © 2016年 chenguibang. All rights reserved.
//

#import "LoginC.h"
#import "TitleTextFiled.h"
#import "UIView+GBExtent.h"
#import "UIView+GBAnimation.h"
#import "GBHudUtil.h"

@interface LoginC ()

@end

@implementation LoginC

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self.contentView sd_resetLayout];
//    self.contentView.sd_layout.leftEqualToView(self.view).topSpaceToView(self.navBar,0).rightEqualToView(self.view).heightIs(self.view.height);
//
   
    

    self.navBar.normalNavBar.titleLable.text = @"登录";
    [[self.navBar.normalNavBar.backBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
   
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
    self.loginView.nameTf.title = @"账号:";
    self.loginView.passwdTf.title = @"密码:";
    
    
    
    [[self.loginView.nameTf rac_textSignal] subscribeNext:^(NSString* x) {
        self.loginVM.name = x;
    }];
    
    [[self.loginView.passwdTf rac_textSignal] subscribeNext:^(NSString* x) {
        self.loginVM.passwd = x;
    }];
    
    
    
    
    
    
    [RACObserve(self.loginVM, name) subscribeNext:^(id x) {
        
    }];
    
    [RACObserve(self.loginVM, passwd) subscribeNext:^(id x) {
        
    }];
    
    
    [[self.loginView.loginBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        
        [self.loginVM signIn];  
        
    }];

    
//    
//   NSTimer*tm = [NSTimer scheduledTimerWithTimeInterval:3
//                                                 target:self selector:@selector(change) userInfo:nil repeats:YES];
//    [[NSRunLoop currentRunLoop] addTimer:tm forMode:NSDefaultRunLoopMode];
    
    [self.loginView updateLayout];
    
}


-(void)change{
    self.hidePartNavBar = !self.hidePartNavBar;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(LoginView *)loginView{
    if (!_loginView) {
        UIImageView *bg = [[UIImageView alloc]initWithFrame:CGRectZero];
//        bg.backgroundColor = UIColorWithRandom;
        [self.contentView addSubview:bg];
        self.contentView.backgroundColor = UIColorWithRGB(248, 255, 244);
        bg.sd_layout.leftEqualToView(self.contentView).topSpaceToView(self.contentView,20).rightEqualToView(self.contentView).heightIs(80);
        bg.image = [UIImage imageNamed:@"logo_02"];
  
        
        _loginView = [[LoginView alloc]init];
        [self.contentView addSubview:_loginView];
        _loginView.sd_layout.leftSpaceToView(self.contentView,20).topSpaceToView(bg,10).rightSpaceToView(self.contentView,20);
        
    }
    return _loginView;
}

-(LoginVM *)loginVM{
    if (!_loginVM) {
        _loginVM = [[LoginVM alloc]init];
    }
    return _loginVM;
}
-(void)viewDidLayoutSubviews{
    [self.loginView.nameTf addBorderWithType:BorderTop|BorderRight|BorderLeft color: UIColorWithString(0xeeeeee) width:1];
    [self.loginView.passwdTf addBorderWithType:BorderAll color: UIColorWithString(0xeeeeee) width:1];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
